/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.EditorPackage;
import editor.Node;
import editor.Relationship;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Node</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.NodeImpl#getName <em>Name</em>}</li>
 *   <li>{@link editor.impl.NodeImpl#getIncomingNode <em>Incoming Node</em>}</li>
 *   <li>{@link editor.impl.NodeImpl#getOutgoingNode <em>Outgoing Node</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class NodeImpl extends EObjectImpl implements Node {
	/**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected static final String NAME_EDEFAULT = null;

	/**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected String name = NAME_EDEFAULT;

	/**
   * The cached value of the '{@link #getIncomingNode() <em>Incoming Node</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getIncomingNode()
   * @generated
   * @ordered
   */
	protected Relationship incomingNode;

	/**
   * The cached value of the '{@link #getOutgoingNode() <em>Outgoing Node</em>}' reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getOutgoingNode()
   * @generated
   * @ordered
   */
	protected EList<Relationship> outgoingNode;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected NodeImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.NODE;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public String getName() {
    return name;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.NODE__NAME, oldName, name));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Relationship getIncomingNode() {
    if (incomingNode != null && incomingNode.eIsProxy())
    {
      InternalEObject oldIncomingNode = (InternalEObject)incomingNode;
      incomingNode = (Relationship)eResolveProxy(oldIncomingNode);
      if (incomingNode != oldIncomingNode)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.NODE__INCOMING_NODE, oldIncomingNode, incomingNode));
      }
    }
    return incomingNode;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Relationship basicGetIncomingNode() {
    return incomingNode;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetIncomingNode(Relationship newIncomingNode, NotificationChain msgs) {
    Relationship oldIncomingNode = incomingNode;
    incomingNode = newIncomingNode;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.NODE__INCOMING_NODE, oldIncomingNode, newIncomingNode);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setIncomingNode(Relationship newIncomingNode) {
    if (newIncomingNode != incomingNode)
    {
      NotificationChain msgs = null;
      if (incomingNode != null)
        msgs = ((InternalEObject)incomingNode).eInverseRemove(this, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, Relationship.class, msgs);
      if (newIncomingNode != null)
        msgs = ((InternalEObject)newIncomingNode).eInverseAdd(this, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, Relationship.class, msgs);
      msgs = basicSetIncomingNode(newIncomingNode, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.NODE__INCOMING_NODE, newIncomingNode, newIncomingNode));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<Relationship> getOutgoingNode() {
    if (outgoingNode == null)
    {
      outgoingNode = new EObjectWithInverseResolvingEList<Relationship>(Relationship.class, this, EditorPackage.NODE__OUTGOING_NODE, EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP);
    }
    return outgoingNode;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.NODE__INCOMING_NODE:
        if (incomingNode != null)
          msgs = ((InternalEObject)incomingNode).eInverseRemove(this, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, Relationship.class, msgs);
        return basicSetIncomingNode((Relationship)otherEnd, msgs);
      case EditorPackage.NODE__OUTGOING_NODE:
        return ((InternalEList<InternalEObject>)(InternalEList<?>)getOutgoingNode()).basicAdd(otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.NODE__INCOMING_NODE:
        return basicSetIncomingNode(null, msgs);
      case EditorPackage.NODE__OUTGOING_NODE:
        return ((InternalEList<?>)getOutgoingNode()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.NODE__NAME:
        return getName();
      case EditorPackage.NODE__INCOMING_NODE:
        if (resolve) return getIncomingNode();
        return basicGetIncomingNode();
      case EditorPackage.NODE__OUTGOING_NODE:
        return getOutgoingNode();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.NODE__NAME:
        setName((String)newValue);
        return;
      case EditorPackage.NODE__INCOMING_NODE:
        setIncomingNode((Relationship)newValue);
        return;
      case EditorPackage.NODE__OUTGOING_NODE:
        getOutgoingNode().clear();
        getOutgoingNode().addAll((Collection<? extends Relationship>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.NODE__NAME:
        setName(NAME_EDEFAULT);
        return;
      case EditorPackage.NODE__INCOMING_NODE:
        setIncomingNode((Relationship)null);
        return;
      case EditorPackage.NODE__OUTGOING_NODE:
        getOutgoingNode().clear();
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.NODE__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case EditorPackage.NODE__INCOMING_NODE:
        return incomingNode != null;
      case EditorPackage.NODE__OUTGOING_NODE:
        return outgoingNode != null && !outgoingNode.isEmpty();
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //NodeImpl
